import 'package:flutter/material.dart';
import 'package:qqmusic/page/home.dart';
import 'package:qqmusic/page/live.dart';
import 'package:qqmusic/page/me.dart';
import 'package:qqmusic/page/mv.dart';
import 'package:qqmusic/page/square.dart';
import 'package:qqmusic/widget/playfloat.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'QQ音乐',
      theme: ThemeData(primaryColor: Color(0xffe2efee)),
      home: Home(),
    );
  }
}

class Home extends StatefulWidget {
  Home({Key key}) : super(key: key);

  @override
  State<Home> createState() => _HomeState();
}

class _HomeState extends State<Home> with TickerProviderStateMixin {
  List<Widget> pages = [home(), live(), mv(), square(), me()];
  TabController controller;
  bool offset = false;
  @override
  void initState() {
    super.initState();
    controller = TabController(length: 5, vsync: this, initialIndex: 0);
    controller.addListener(() {
      if (controller.indexIsChanging) {
        if (controller.index == 2) {
          this.offset = true;
        } else {
          this.offset = false;
        }
        setState(() {});
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      // backgroundColor: Theme.of(context).primaryColor,
      body: Stack(
        children: [
          Container(
            decoration: BoxDecoration(
                // color: Colors.transparent,
                gradient: LinearGradient(
                    begin: Alignment.topLeft,
                    end: Alignment.bottomLeft,
                    colors: [Colors.yellow, Colors.white])),
          ),
          Container(
            constraints: BoxConstraints(),
            // decoration: BoxDecoration(
            //     color: Colors.transparent,
            //     gradient: LinearGradient(
            //         begin: Alignment.topLeft,
            //         end: Alignment.bottomLeft,
            //         colors: [Color(0xffe2f1ee), Colors.white])),
            child: TabBarView(
              children: pages,
              controller: controller,
              physics: NeverScrollableScrollPhysics(),
            ),
          ),
          Positioned(
              bottom: 0,
              child: Offstage(
                child: palyfloat(),
                offstage: offset,
              )),
        ],
      ),
      bottomNavigationBar: BottomAppBar(
        child: Container(
          padding: EdgeInsets.only(top: 10),
          height: 60,
          child: Theme(
            data: ThemeData(
                splashColor: Colors.transparent,
                highlightColor: Colors.transparent),
            child: TabBar(
              controller: controller,
              labelColor: Color(0xff00dd7d),
              unselectedLabelColor: Color(0xffc6c6c6),
              indicator: BoxDecoration(),
              tabs: [
                Column(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Icon(
                      Icons.music_note,
                      color: Color(0xffc6c6c6),
                      size: 30,
                    ),
                    Text(
                      '首页',
                      style: TextStyle(fontSize: 12),
                    )
                  ],
                ),
                Column(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Icon(
                      Icons.remove_red_eye,
                      color: Color(0xffc6c6c6),
                      size: 30,
                    ),
                    Text(
                      '直播',
                      style: TextStyle(fontSize: 12),
                    )
                  ],
                ),
                Column(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Icon(
                      Icons.live_tv,
                      color: Color(0xffc6c6c6),
                      size: 30,
                    ),
                    Text(
                      'MV',
                      style: TextStyle(fontSize: 12),
                    )
                  ],
                ),
                Column(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Icon(
                      Icons.save,
                      color: Color(0xffc6c6c6),
                      size: 30,
                    ),
                    Text(
                      '社区',
                      style: TextStyle(fontSize: 12),
                    )
                  ],
                ),
                Column(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Icon(
                      Icons.face,
                      color: Color(0xffc6c6c6),
                      size: 30,
                    ),
                    Text(
                      '我的',
                      style: TextStyle(fontSize: 12),
                    )
                  ],
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
